﻿using System;
using System.Collections.Generic;

namespace PlottingBasics.LINQHelpers
{
    public static class ZipperClass
    {
        public static IEnumerable<Pair<T1, T2>> Zipper<T1, T2>(this IEnumerable<T1> s1, IEnumerable<T2> s2)
        {
            return new ZipperItr<T1, T2> (s1, s2);
        }

        class ZipperItr<T1, T2> : IEnumerable<Pair<T1, T2>>
        {
            private IEnumerable<T1> s1;
            private IEnumerable<T2> s2;

            public ZipperItr(IEnumerable<T1> s1, IEnumerable<T2> s2)
            {
                // TODO: Complete member initialization
                this.s1 = s1;
                this.s2 = s2;
            }

            public System.Collections.Generic.IEnumerator<Pair<T1,T2>> GetEnumerator()
            {
                var itr1 = s1.GetEnumerator();
                var itr2 = s2.GetEnumerator();

                while (itr1.MoveNext() && itr2.MoveNext())
                {
                    yield return new Pair<T1, T2>(itr1.Current, itr2.Current);
                }
            }


            #region IEnumerable Members

            System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
            {
                throw new NotImplementedException();
            }

            #endregion
        }
    }
}
